package com.entor.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSON;
import com.entor.model.Msg;
import com.entor.model.Thought;
import com.entor.service.BaseServiceI;

@Controller
@RequestMapping("/tc")
public class ThoughtController extends BaseController<Thought>{
	
	@Resource(name="thoughtService")
	private BaseServiceI<Thought> bai;
	
	
	@RequestMapping("/index")
	public String index(){
		
		return "/thought/index";
		
	}
	
	@Override
	public List<Thought> find(Thought t){
		
		List list = bai.find(t);
		
		return list;
		
	}
	
	@Override
	public Msg remove(@PathVariable(value="id") Integer id){
		
		Msg m = bai.remove(id);
		return m;
		
		
	}
	
	
	@Override
	public Msg insert(Thought n,@RequestParam(required=false,value="files") MultipartFile[] files){
		
		Msg m = bai.insert(n);
		
		return m;
	}
	
	
	
	@RequestMapping("/getThought")
	@ResponseBody
	public Thought getThought(Integer index){
		
		List<Thought> list = bai.find(new Thought());
		Thought m = list.get(index);
		
		return m;
	}
	
	
	@RequestMapping("/shownotices")
	public String show(Integer index,HttpServletRequest req){
		
		List<Thought> list = bai.find(new Thought());
		
		Thought n = list.get(index);
		req.setAttribute("thought", list.size());
		req.setAttribute("n", n);
		req.setAttribute("i", index);
		
		return "/thought/showThought";
	}
	
	

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

}
